module Tomahawk
  module Generators
    class Base
      include Generators

      def initialize(directive_group)
        @directive_group = directive_group
      end

      def to_str
        config = "\n<#{directive_group_name} #{@directive_group.parameters}>\n"

        @directive_group.directives.each do |directive, value|
          config += generate_directive(directive, value)
        end

        @directive_group.groups.each do |group|
          config += group.to_s
        end

        config += "\n</#{directive_group_name}>\n"
      end

      alias_method :to_s, :to_str
    end

    def directive_group_name
      @directive_group.name
    end
  end
end
